package com.teyao.teyao_back.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.teyao.teyao_back.entity.DeliverOrder;
import com.teyao.teyao_back.service.DeliverOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RequestMapping("/deliverOrder")
@RestController
public class DeliverOrderController {
    @Autowired
    private DeliverOrderService deliverOrderService;


    @PostMapping("/setStatus32")
    public boolean setStatus32(String orderId) {
        UpdateWrapper updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("order_id", orderId);//更新条件
        DeliverOrder deliverOrder = new DeliverOrder();
        deliverOrder.setStatuId(32);
        return deliverOrderService.update(deliverOrder, updateWrapper);
    }

    //分配司机
    @PostMapping("/addDriver")
    public boolean addDriver(String orderId, Integer driverId) {
        UpdateWrapper updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("order_id", orderId);//更新条件
        DeliverOrder deliverOrder = new DeliverOrder();
        deliverOrder.setDriverId(driverId);

        return deliverOrderService.update(deliverOrder, updateWrapper);
    }

    @PostMapping("/updateStatus")
    public boolean updateStatus(String orderId, Integer statusId) {
        UpdateWrapper updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("order_id", orderId);//更新条件
        DeliverOrder deliverOrder = new DeliverOrder();
        deliverOrder.setStatuId(statusId);
        return deliverOrderService.update(deliverOrder, updateWrapper);
    }

    @PostMapping("/insert")
    public boolean insert(String orderId, Integer statusId) {
        DeliverOrder deliverOrder = new DeliverOrder();
        deliverOrder.setStatuId(statusId);
        deliverOrder.setOrderId(orderId);
        return deliverOrderService.save(deliverOrder);
    }

    @PostMapping("/updatePosition")
    public boolean updatePosition(String orderId, String position) {
        UpdateWrapper updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("order_id", orderId);//更新条件
        DeliverOrder deliverOrder = new DeliverOrder();
        deliverOrder.setPosition(position);
        return deliverOrderService.update(deliverOrder, updateWrapper);
    }
}
